package cn.net.qinling.healthcare.test.datagen;

import java.util.ArrayList;
import java.util.List;

public abstract class Generator<T> {

	protected Selector selector = null;
	
	protected volatile T lastProduct = null;

	public Generator(Selector selector) {
		this.selector = selector;
	}
	
	protected abstract T doGeneration();

	public T generate() {
		T result = doGeneration();
		
		if (null != result) {
			this.lastProduct = result;
		}
		
		return result;
	}

	public List<T> generate(int n) {
		List<T> result = new ArrayList<T>();
		for (int i = 0; i < n; i++) {
			result.add(this.generate());
		}

		return result;
	}
	
	public T getLastProduct() {
		return this.lastProduct;
	}
}
